home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
476-500
/
disk_497
/
nlcalc
/
source
/
ckeys.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
6KB
|
203 lines
/*
* CALC Provides a calculator that opens on the active screen when
* you press a specific key sequence. Otherwise, the program
* waits quitely in the background.
*
* Copyright 1989 by Davide P. Cervone.
* You may use this code, provided this copyright notice is kept intact.
*/
#define INTUITION_PREFERENCES_H /* don't need 'em */
#include <intuition/intuition.h>
#include "cHandler.h"
#include "cKeys.h"
#define UPWIDTH 24
#define UPHEIGHT 10
#define UPDEPTH 2
#define UPWORDS 2
#define DOWNWIDTH 24
#define DOWNHEIGHT 10
#define DOWNDEPTH 2
#define DOWNWORDS 2
#define CLOSEWIDTH 21
#define CLOSEHEIGHT 10
#define CLOSEDEPTH 2
#define CLOSEWORDS 2
#ifndef NL_DAEMON
extern USHORT UpFrontData[UPDEPTH][UPHEIGHT*UPWORDS];
extern USHORT DownBackData[DOWNDEPTH][DOWNHEIGHT*DOWNWORDS];
extern USHORT CloseData[CLOSEDEPTH][CLOSEHEIGHT*CLOSEWORDS];
struct Image UpFrontImage =
{0,0, UPWIDTH,UPHEIGHT,UPDEPTH, &UpFrontData[0][0], 0x03,0x00, NULL};
struct Image DownBackImage =
{0,0, DOWNWIDTH,DOWNHEIGHT,DOWNDEPTH, &DownBackData[0][0], 0x03,0x00, NULL};
struct Image CloseImage =
{0,0, CLOSEWIDTH,CLOSEHEIGHT,CLOSEDEPTH, &CloseData[0][0], 0x03,0x00, NULL};
#endif
#define TOPBOX(w,h) {0,0, 0,h-1, 1,h-2, 1,0, w-2,0}
#define BOTBOX(w,h) {w-1,h-1, w-1,0, w-2,1, w-2,h-1, 1,h-1}
#define BUTTONBOX(w,h) {TOPBOX(w,h),BOTBOX(w,h)}
static SHORT KeyBox[2][10] = BUTTONBOX(KEYW,KEYH);
static SHORT LongBox[2][10] = BUTTONBOX(LONGKEYW,LONGKEYH);
static SHORT TallBox[2][10] = BUTTONBOX(TALLKEYW,TALLKEYH);
static SHORT TextBox[2][10] = BUTTONBOX(DISPLAYW,DISPLAYH);
static SHORT KPadBox[2][10] = BUTTONBOX(KPADW,KPADH);
static SHORT FKeyBox[2][10] = BUTTONBOX(FKPDW,FKPDH);
static SHORT MainBox[2][10] = /* can't use BUTTON: too long for preprocessor */
{TOPBOX(IMAGEW,IMAGEH),
BOTBOX(IMAGEW,IMAGEH)};
static SHORT RootBox[] = {10,0, 4,6, 1,3, 0,3, 3,6, 9,0, 17,0};
static SHORT DragBox[] = {CLOSEWIDTH+9,0, WINDW-UPWIDTH-DOWNWIDTH-9,0};
#define NEXTBORDER(id) NULL
#define OUTBUTTON(id,x,y,box)\
{x,y, LIGHTPEN,0, JAM1, 5, &box[0][0], NEXTBORDER(id)},\
{x,y, DARKPEN,0, JAM1, 5, &box[1][0], &CalcBorder[id-1]}
#define INBUTTON(id,x,y,box)\
{x,y, DARKPEN,0, JAM1, 5, &box[0][0], NEXTBORDER(id)},\
{x,y, LIGHTPEN,0, JAM1, 5, &box[1][0], &CalcBorder[id-1]}
#define ROOTBRDR(id,x,y)\
{x,y, TEXTPEN,0, JAM1, 7, &RootBox[0], &CalcBorder[BRDR_KEY]}
#define DRAGBRDR(id,box)\
{0,4, LIGHTPEN,0,JAM1, 2, &box[0], NULL},\
{0,8, LIGHTPEN,0,JAM1, 2, &box[0], &CalcBorder[id-1]}
struct Border CalcBorder[] =
{
OUTBUTTON (BRDR_KEY, 0,0, KeyBox),
OUTBUTTON (BRDR_LONG, 0,0, LongBox),
OUTBUTTON (BRDR_TALL, 0,0, TallBox),
ROOTBRDR (BRDR_ROOT, 4,2),
#undef NEXTBORDER
#define NEXTBORDER(id) &CalcBorder[id-2]
DRAGBRDR (BRDR_DRAG, DragBox),
INBUTTON (BRDR_TEXT, DISPX,DISPY, TextBox),
INBUTTON (BRDR_KPAD, KPXPOS,KPYPOS, KPadBox),
INBUTTON (BRDR_FKEY, FKXPOS,FKYPOS, FKeyBox),
INBUTTON (BRDR_DISP, DISPXPOS,DISPYPOS, FKeyBox),
OUTBUTTON (BRDR_MAIN, 0,TOPH, MainBox)
};
static struct Image BgImage = {0,TOPH, IMAGEW,IMAGEH,0, NULL, 0,BACKPEN, NULL};
static struct Image TextImage =
{LINEW,LINEH, DISPLAYIW,DISPLAYIH,0, NULL, 0,DISPLAYPEN, NULL};
static struct TextAttr KeyFont = {"topaz.font",8,0,NULL};
char DisplayBuffer[20] = "-0.";
#define KEY_TEXT(s,n,x,y)\
{TEXTPEN,0,JAM1, (x-n*8)/2,(y-8)/2+1, &KeyFont, s, NULL}
#define DISPNAME(s,n,x,y)\
{DISPTEXTPEN,0,JAM1, x-n*8-2*LINEW,(y-8)/2+1, &KeyFont, s, NULL}
#define KEYNAME(s,n) KEY_TEXT(s,n,KEYW,KEYH)
#define LONGNAME(s,n) KEY_TEXT(s,n,LONGKEYW,LONGKEYH)
#define TALLNAME(s,n) KEY_TEXT(s,n,TALLKEYW,TALLKEYH)
struct IntuiText KeyText[] =
{
LONGNAME("0",1),
KEYNAME("1",1),
KEYNAME("2",1),
KEYNAME("3",1),
KEYNAME("4",1),
KEYNAME("5",1),
KEYNAME("6",1),
KEYNAME("7",1),
KEYNAME("8",1),
KEYNAME("9",1),
KEYNAME(".",1),
KEYNAME("+",1),
KEYNAME("-",1),
KEYNAME("*",1),
KEYNAME("/",1),
KEYNAME("(",1),
KEYNAME(")",1),
TALLNAME("=",1),
KEYNAME("+-",2),
KEYNAME("",0),
KEYNAME("%",1),
KEYNAME("C",1),
DISPNAME(&DisplayBuffer[1],2,DISPLAYW,DISPLAYH),
};
#define NEXTGADGET(id) &CalcGadget[id+1]
#define KEY(id,x,y,w,h,c,brdr)\
{NEXTGADGET(id), x,y, w,h, GADGHCOMP, RELVERIFY,\
BOOLGADGET, (APTR)&CalcBorder[brdr], NULL, &KeyText[id],\
NULL, NULL, id, (APTR)c}
#define DISPLAY(id,c)\
{NEXTGADGET(id), DISPX,DISPY, DISPLAYW,DISPLAYH, GADGHCOMP|GADGIMAGE,\
RELVERIFY, BOOLGADGET, (APTR)&TextImage, NULL, &KeyText[id],\
NULL, NULL, id, (APTR)c}
#define BRDRGADGET(id)\
{NEXTGADGET(id), 0,0, 0,0, GADGHNONE, 0, BOOLGADGET,\
(APTR)&CalcBorder[BRDR_MAIN], NULL, NULL, NULL, NULL, id, NULL}
#define BGGADGET(id)\
{NULL, 0,0, 0,0, GADGHNONE| GADGIMAGE, 0, BOOLGADGET, (APTR)&BgImage,\
NULL, NULL, NULL, NULL, id, NULL}
#define KPKEY(id,r,c,ch) KEY(id,KPX(c),KPY(r),KEYW,KEYH,ch,BRDR_KEY)
#define LONGKEY(id,r,c,ch) KEY(id,KPX(c),KPY(r),LONGKEYW,LONGKEYH,ch,BRDR_LONG)
#define TALLKEY(id,r,c,ch) KEY(id,KPX(c),KPY(r),TALLKEYW,TALLKEYH,ch,BRDR_TALL)
#define FKEY(id,r,c,ch) KEY(id,FKX(c),FKY(r),KEYW,KEYH,ch,BRDR_KEY)
#define RKEY(id,r,c,ch) KEY(id,FKX(c),FKY(r),KEYW,KEYH,ch,BRDR_ROOT)
struct Gadget CalcGadget[] =
{
LONGKEY (KEY_0, 4,0, '0'),
KPKEY (KEY_1, 3,0, '1'),
KPKEY (KEY_2, 3,1, '2'),
KPKEY (KEY_3, 3,2, '3'),
KPKEY (KEY_4, 2,0, '4'),
KPKEY (KEY_5, 2,1, '5'),
KPKEY (KEY_6, 2,2, '6'),
KPKEY (KEY_7, 1,0, '7'),
KPKEY (KEY_8, 1,1, '8'),
KPKEY (KEY_9, 1,2, '9'),
KPKEY (KEY_DOT, 4,2, '.'),
KPKEY (KEY_PLUS, 2,3, '+'),
KPKEY (KEY_MINUS, 1,3, '-'),
KPKEY (KEY_TIMES, 0,3, '*'),
KPKEY (KEY_DIVIDE, 0,2, '/'),
KPKEY (KEY_LPAREN, 0,0, '('),
KPKEY (KEY_RPAREN, 0,1, ')'),
TALLKEY (KEY_EQUAL, 3,3, '='),
FKEY (KEY_SIGN, 0,0, '\\'),
RKEY (KEY_SQRT, 0,1, '`'),
FKEY (KEY_PERCENT,0,2, '%'),
FKEY (KEY_CLEAR, 0,3, '\x7F'),
DISPLAY (KEY_DISP, '\x08'),
BRDRGADGET (GADG_BRDR),
BGGADGET (GADG_BCKGRND)
};